$(function () {
	var app = new Vue({
		el:'#app',
		data:{
			table:{},
			form:{},
			queryData:{}
		},
		methods: {
			init:function () {
				var vm = this;
				layui.use(['table','form','layer'], function(){
					  var table = layui.table;
					  var form = layui.form;
					  vm.table = table;
					  vm.form = form;
					  //第一个实例
					  table.render({
						 id:"resourceInfoDatagrid"
					    ,elem: '#datagrid'
					    ,height: 355
					    ,url: staticURL+'/basic/resourceInfoAction/datagrid.do' //数据接口
					    ,limit:10
					    ,page: true //开启分页
					    ,cols: [[ //表头
					    	{field: '', title: '',checkbox: true, }
						      ,{field: 'id', title: 'ID',}
						      ,{field: 'name', title: '资源名称', }
						      ,{field: 'description', title: '资源描述',  }
						      ,{field: 'url', title: '资源地址', } 
						      ,{field: 'type', title: '资源类型',  templet: function(d){
						    	  if(d.type == '0'){
						    		return  'URL资源';
						    	  } else if(d.type == '1'){
						    		return  '组件资源';
						    	  } else if(d.type == '2'){
						    		return  '模块资源';
						    	  } else {
						    		return  '待办资源';
						    	  }
						      }}
						      ,{field: 'status', title: '资源状态 ', templet: function(d){
						    	  if(d.status == '1'){
							    		 return  '有效';
						    		  } else {
						    			 return  '无效';
						    		  }
							   }}
						      ,{field: 'code', title: '资源编码', }
						      ,{field: 'orderIndex', title: '排序号', }
						      ,{field: 'parentName', title: '所在模块', }
						      ,{field: 'imgName', title: '图标', }
					    ]]
					    ,response:{
				   		  msgName: 'msg' //状态信息的字段名称，默认：msg
				   		  ,countName: 'total' //数据总数的字段名称，默认：count
				   		  ,dataName: 'rows' //数据列表的字段名称，默认：data
				   		} 
					    ,request: {
						  pageName: 'page' //页码的参数名称，默认：page
						  ,limitName: 'rows' //每页数据量的参数名，默认：limit
						}
					  });
					});
			},
			query:function () {
				this.table.reload('resourceInfoDatagrid', {
					  where: this.queryData
				});
			},
			addItem:function(){
				layer.open({
					  type: 2, 
					  title:false,
					  area:['100%','100%'],
					  offset:["0px","0px"],
					  icon:0,
					  closeBtn: 0,
					  content: staticURL+'/basic/resourceInfoAction/goHandle',
					  end:function(){
					  }
					}); 
			},
			editItem:function(){
				var rows = this.table.checkStatus('resourceInfoDatagrid').data;
				if (rows.length == 1) {
					layer.open({
						  type: 2, 
						  title:false,
						  area:['100%','100%'],
						  offset:["0px","0px"],
						  icon:0,
						  closeBtn: 0,
						  content: staticURL+'/basic/resourceInfoAction/goHandle?id='+rows[0].id,
						  end:function(){
							//  _search();
						  }
						}); 
				}else {
					layer.alert('请选择一项要编辑的记录！', {icon: 8});
				}
			},
			deleteItem:function(){
				var rows = this.table.checkStatus('resourceInfoDatagrid').data;
				var ids = "";
				if (rows.length > 0) {
					layer.confirm('您要删除当前所选项目？', {
						  btn: ['确定','取消'] //按钮
						}, function(){
							for ( var i = 0; i < rows.length; i++) {
								if (i != rows.length - 1)
									ids = ids + "ids=" + rows[i].id + "&";
								else
									ids = ids + "ids=" + rows[i].id;
							}
							$.ajax({
								url : staticURL+'/basic/resourceInfoAction/delete',
								data : ids,
								dataType : 'json',
								success : function(response) {
									app.query();
									layer.msg('删除成功！', {icon: 6});
								}
							});
						}, function(){
					  	}
					  );
				} else {
					layer.alert('请选择要删除的记录！', {icon: 8});
				}
			}
		},
		created: function () {
			this.init();
			window._refresh = this.query;
		},
		updated:function(){
		}
	});
});